﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace HelperLib
{
   public class XMLWriter
   {
      private readonly XmlSerializer serializer;
      private FileStream filestream;

      public XMLWriter()
      {
         serializer = new XmlSerializer(typeof(List<KukaCoordData>));
      }

      public bool writeData(string filepath, List<KukaCoordData> coords, out string output)
      {
         try
         {
            filestream = new FileStream(@filepath, FileMode.Create);
            serializer.Serialize(filestream, coords);
            filestream.Close();

            output = "Coordinates saved in XML-file.";
            return true;
         }
         catch (Exception ex)
         {
            filestream.Close();
            output = "- Error - " + ex.Message;
            MessageBox.Show(ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         return false;
      }
   }
}
